use chrono::{Datelike, Duration, Local, TimeZone, Utc};
use std::ops::Add;

pub struct Date {
    pub year: u16,
    pub month: u8,
    pub day: u8,
}
impl Date {
    pub fn new(year: u16, month: u8, day: u8) -> Date {
        Date { year, month, day }
    }
    pub fn as_quote_date(&self) -> String {
        format!("{}{:02}{:02}", self.year, self.month, self.day)
    }
    pub fn now() -> Date {
        let date = Utc::now();
        Date {
            year: date.year() as u16,
            month: date.month() as u8,
            day: date.day() as u8,
        }
    }

    pub fn days_ago(days: u32) -> Date {
        let date = Local::now();
        let date = date - Duration::days(days as i64);
        Date {
            year: date.year() as u16,
            month: date.month() as u8,
            day: date.day() as u8,
        }
    }
}
